﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using RBS.Common;
using RBS.Web.Hotel.Controllers;
using Webdiyer.WebControls.Mvc;

namespace RBS.Web.Hotel.Areas.Chart.Controllers
{
    public class DeedController : BaseController
    {
        //
        // GET: /Chart/Deed/ 
        public ActionResult AdvChart(int page = 0, string kword = null)
        {
            return View(PaymentList(3, page, kword)); 
        } 
        /// <summary>
        /// 送菜券
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult SfChart(int page = 0, string kword=null)
        {
            return View(PaymentList(1, page, kword)); 
        }

        public ActionResult CpChart(int page = 0, string kword = null)
        {
            return View(PaymentList(1, page, kword));
        }
        public PagedList<RBS.Core.Model.P_Advertis_Payment> PaymentList(int type = 0, int id = 1, string kword = null)
        {
            const int pageSize = 10;
            var bll = new RBS.Core.BLL.P_Advertis_Payment();
            if (kword != null) kword = kword.Replace("'", "");
            var strTemp = new StringBuilder();
            if (!string.IsNullOrEmpty(kword))
            {
                //strTemp.Append(" and (H_UID like  '%" + kword + "%' or H_UserName like '%" + kword + "%')");
            }
            string strWhere = " and HotelId=" + CurrentUser.HotelId + strTemp.ToString();
            if (type != 0)
            {
                strWhere += " and DeedType=  " + type + "";
            }
            const string orderby = " id  desc";
            var startIndex = id;
            int totalItems = 0; //要分页的总记录数
            DataTable dt = bll.GetList(pageSize, startIndex, strWhere, orderby, out totalItems).Tables[0];
            //PagedList构造函数 
            var list = IListDataSet.DataTableToIList<RBS.Core.Model.P_Advertis_Payment>(dt);
            PagedList<RBS.Core.Model.P_Advertis_Payment> arts = null;
            if (list != null)
                arts = new PagedList<RBS.Core.Model.P_Advertis_Payment>(list, id, pageSize, totalItems);
            else
            {
                list = new List<RBS.Core.Model.P_Advertis_Payment>();
                arts = new PagedList<RBS.Core.Model.P_Advertis_Payment>(list, id, pageSize, totalItems);
            }
            return arts;
        }
        
    }
}
